﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using Arizu.Repository;

namespace AiRiZu.User.handler
{
    public class UpdateAdvancedFixedPricing : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Session["logId"] == null)
            {
                return;
            }

            AirizuRoom airizuRoom = AirizuRoom.CreateInstance();

            if (context.Request.Params["additionalFee"] != null)
            {
                if (!string.IsNullOrEmpty(context.Request.Params["roomId"].ToString()) && !string.IsNullOrEmpty(context.Request.Params["additionalFee"].ToString()))
                {
                    airizuRoom.UpdateExtraRent(long.Parse(context.Request.Params["roomId"].ToString()), int.Parse(context.Request.Params["additionalFee"].ToString()));
                } 
            }

            if (context.Request.Params["additionalGuestNo"] != null && context.Request.Params["additionalGuestPricing"] != null)
            {
                if (!string.IsNullOrEmpty(context.Request.Params["roomId"].ToString()) && !string.IsNullOrEmpty(context.Request.Params["additionalGuestPricing"].ToString()) && !string.IsNullOrEmpty(context.Request.Params["additionalGuestNo"].ToString()))
                {
                    airizuRoom.UpdateExtraRent(long.Parse(context.Request.Params["roomId"].ToString()), int.Parse(context.Request.Params["additionalGuestPricing"].ToString()), int.Parse(context.Request.Params["additionalGuestNo"].ToString()));
                }
            }

            if (context.Request.Params["monthlyPricing"] != null && context.Request.Params["additionalMonthlyPricing"] != null)
            {
                if (!string.IsNullOrEmpty(context.Request.Params["roomId"].ToString()) && !string.IsNullOrEmpty(context.Request.Params["monthlyPricing"].ToString()) && !string.IsNullOrEmpty(context.Request.Params["additionalMonthlyPricing"].ToString()))
                {
                    airizuRoom.UpdateMonthRent(long.Parse(context.Request.Params["roomId"].ToString()), int.Parse(context.Request.Params["monthlyPricing"].ToString()), int.Parse(context.Request.Params["additionalMonthlyPricing"].ToString()));
                }
            }

            if (context.Request.Params["weeklyPricing"] != null && context.Request.Params["additionalWeeklyPricing"] != null)
            {
                if (!string.IsNullOrEmpty(context.Request.Params["roomId"].ToString()) && !string.IsNullOrEmpty(context.Request.Params["weeklyPricing"].ToString()) && !string.IsNullOrEmpty(context.Request.Params["additionalWeeklyPricing"].ToString()))
                {
                    airizuRoom.UpdateMonthRent(long.Parse(context.Request.Params["roomId"].ToString()), int.Parse(context.Request.Params["weeklyPricing"].ToString()), int.Parse(context.Request.Params["additionalWeeklyPricing"].ToString()));
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
